<template>
	<view class="content">
		<button class="size" @tap="getProximity">获取当前设备的接近距离信息</button>
		<button class="size" @tap="watchProximity">监听设备接近距离的变化</button>
		<button class="size" @tap="clearWatch">关闭监听设备接近距离变化

</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				watchId: null
			}
		},
		onLoad() {

		},
		methods: {
			getProximity() {
				plus.proximity.getCurrentProximity(function(d) {
					console.log("Get distance success: " + d);
				}, function(e) {
					console.log("Error: " + e.message);
				});
			},
			watchProximity() {
				this.watchId = plus.proximity.watchProximity(function(d) {
					console.log(d)
				}, function(e) {
					console.log("Error: " + e.message);
				});
			},
			clearWatch(){
				plus.proximity.clearWatch( this.watchId )
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
